package com.vpx.server.service.system.impl;

import javax.annotation.Resource;

import com.vpx.server.mapper.system.SysUidMapper;
import com.vpx.server.service.system.SysUidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author xx
 * @title: vpx
 * @module 
 * @description: 
 * @date 
 */
@Service
public class SysUidServiceImpl implements SysUidService {
	@Autowired
	SysUidMapper sysUidMapper;


	/**
	 * @param type
	 * @return
	 * @throws Exception
	 */
	@Override
	@Transactional(rollbackFor=Exception.class,propagation = Propagation.REQUIRES_NEW)
	public long getNextNum(String type) {
		return getNextNum(type, 1);
	}

	/**
	 * @param type
	 * @param num
	 * @return
	 * @throws Exception
	 */
	@Override
	@Transactional(rollbackFor=Exception.class,propagation = Propagation.REQUIRES_NEW)
	public long getNextNum(String type, int num) {
		long retNum = 0;
		try{
			retNum = sysUidMapper.queryAppointNextNum(type, "1");

			sysUidMapper.updateAppointNextNum(type, num + "");

		}catch(Exception e){
			e.printStackTrace();
			throw new RuntimeException(e);
		}

		return retNum;
	}

}
